<template>
  <transition name="slide">
    <div class="add-song" v-show="showFlag" @click.stop>
      <div class="header">
        <h1 class="title">添加歌曲到列表</h1>
        <div class="close" @click.stop="hide">
          <i class="iconfont icon-hebingxingzhuang-copy-copy"></i>
        </div>
      </div>
      <div class="search-box-wrapper">
        <!-- 搜索组件 -->
        <search-box placeholder="搜索歌曲" @query="onQueryChange" ref="SearchBox"></search-box>
      </div>
      <div class="shortcut" v-show="!query">
        <Switches :switches="switches" :currentIndex="currentIndex" @switch="switchItem"></Switches>
        <div class="list-wrapper">
          <scroll
            ref="songListScroll"
            :data="playHistory"
            v-if="currentIndex === 0"
            class="list-scroll"
          >
            <div class="list-inner">
              <song-list :songs="playHistory" @toplay="selectSong"></song-list>
            </div>
          </scroll>
          <scroll
            ref="searchListScroll"
            class="list-scroll"
            v-if="currentIndex === 1"
            :data="searchHistory"
            :delayTime="delayTime"
          >
            <div class="list-inner">
              <search-list
                :searches="searchHistory"
                @select="searchToInpput"
                @delete="delete_historyOne"
              ></search-list>
            </div>
          </scroll>
        </div>
      </div>
      <div class="search-result" v-show="query">
        <!-- 搜索结果组件 -->
        <suggest
          :query="query"
          :showSinger="showSinger"
          @listScroll="blurInput"
          @selectSearch="search"
        ></suggest>
      </div>
      <!-- 添加歌曲到列表的提示弹窗 -->
      <top-tip ref="topTip">
        <div class="tip-title">
         <i class="icon-ok"></i>
         <span class="text">1首歌曲已经添加到播放队列</span>
        </div>
      </top-tip>
    </div>
  </transition>
</template>
<script>
import searchBox from "@/components/searchbox/searchbox";
import suggest from "@/components/suggest/suggest";
import { searchMixin,songListMixin } from "@/common/js/mixin";
import Switches from "@/base/switches/switches";
import scroll from "@/base/scroll/scroll";
import { mapGetters, mapActions } from "vuex";
import songList from "@/base/song-list/song-list";
import Song from "@/common/js/SongObject";
import searchList from "@/base/search-list/search-list";
import topTip from "@/base/top-tip/top-tip";
export default {
  mixins: [searchMixin,songListMixin],
  data() {
    return {
      showFlag: false, //控制组件的显示与隐藏
      // query:'',//搜索的关键词
      showSinger: false, //不显示搜索出的歌手
      // currentIndex: 0,
      switches: [{ name: "最近播放" }, { name: "搜索历史" }],
     
    };
  },
  computed: {
    ...mapGetters(["playHistory", "searchHistory"])
  },
  components: {
    searchBox,
    suggest,
    Switches,
    scroll,
    songList,
    searchList,
    topTip
  },
  methods: {
    show() {
      this.showFlag = true;
      setTimeout(() => {
        if (this.currentIndex === 0) {
          this.$refs.songListScroll.refresh();
        } else {
          this.$refs.searchListScroll.refresh();
        }
      }, 20);
    },
    hide() {
      this.showFlag = false;
    },
    search(query) {
      this.saveSearch();
    },
    // // 切换switch-Item
    // switchItem(index) {
    //   this.currentIndex = index;
    // },
    // // 将选中的歌曲插入到播放列表当中
    // selectSong(obj) {
    //   console.log(obj);
    //   let song = obj.song;
    //   if (obj.index > 0) {
    //     this.insertSong(new Song(song));
    //     this.showTopTip()
    //   }
    // },
    // 
    showTopTip(){
      this.$refs.topTip.show()
    },
    // ...mapActions(["insertSong"])
  }
};
</script>
<style lang="stylus">
@import '../../common/stylus/variable';
@import '../../common/stylus/mixin';

.add-song {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 100%;
  z-index: 999;
  background: $color-background;

  &.slide-enter-active, &.slide-leave-active {
    transition: all 0.3s;
  }

  &.slide-enter, &.slide-leave-to {
    transform: translate3d(100%, 0, 0);
  }

  .header {
    position: relative;
    height: 44px;
    text-align: center;
    line-height: 44px;

    .title {
      line-height: 44px;
      font-size: $font-size-large;
      color: $color-text;
    }

    .close {
      position: absolute;
      top: 0;
      right: 8px;

      .iconfont {
        display: block;
        padding: 12px;
        font-size: 20px;
        color: $color-theme;
      }
    }
  }

  .search-box-wrapper {
    margin: 20px;
  }

  .shortcut {
    .list-wrapper {
      position: absolute;
      top: 165px;
      bottom: 0;
      width: 100%;

      .list-scroll {
        height: 100%;
        overflow: hidden;

        .list-inner {
          padding: 20px 30px;
        }
      }
    }
  }

  .search-result {
    position: fixed;
    top: 124px;
    bottom: 0;
    width: 100%;
  }

  .tip-title {
    text-align: center;
    padding: 18px 0;
    font-size: 0;

    .icon-ok {
      font-size: $font-size-medium;
      color: $color-theme;
      margin-right: 4px;
    }

    .text {
      font-size: $font-size-medium;
      color: $color-text;
    }
  }
}
</style>